#!/usr/bin/python

#fetches the atom feeds to check for new mails
#also parses the mails using feedparser
#Gets the gmail credentials from gnome-keyring using cred.py

import cred
import urllib2
import feedparser


#the following function fetches the feed using the Gmail a/c credentials
def fetch_feeds(f,u,p):
	password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
	password_mgr.add_password(None,f,u,p)
	handler=urllib2.HTTPBasicAuthHandler(password_mgr)
	opener=urllib2.build_opener(handler)
	urllib2.install_opener(opener)
	return urllib2.urlopen(f)

#parse the fetched feeds and returns the parsed entries
def GetFeeds():
	creds=cred.GetCred(0)
	feed = """https://mail.google.com/mail/feed/atom"""
	mails=fetch_feeds(feed,creds[0],creds[1])
	parsed=feedparser.parse(mails)
	return parsed

